<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Collection;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Support\Facades\DB;

class Inventory extends Authenticatable
{
    use Notifiable,HasRoles;

    protected $table = 'inventory';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */


    public function getRkTotalList($where,$search,$page,$limit)
    {

        $result =  DB::table('v_rk_total')
            ->where(function($query) use($search) {
                if (!empty($search['date'])) {
                    $query->where('data_time',$search['date']);
                }
                if (!empty($search['yao_supplier_name'])) {
                    $query->where('yao_supplier_name', 'like', '%' . $search['yao_supplier_name'] . '%');
                }
                if (!empty($search['ytx_code'])) {
                    $query->where('ytx_code',  $search['ytx_code']);
                }
            })
            ->select('*')
            ->orderBy('jin_supplier_code','asc')
            ->offset($page)->limit($limit)

            ->get()->toArray();

        $count = DB::table('v_rk_total')
            ->where(function($query) use($search) {
                if (!empty($search['date'])) {
                    $query->where('data_time',$search['date']);
                }
                if (!empty($search['yao_supplier_name'])) {
                    $query->where('yao_supplier_name', 'like', '%' . $search['yao_supplier_name'] . '%');
                }
                if (!empty($search['ytx_code'])) {
                    $query->where('ytx_code',  $search['ytx_code']);
                }

            })
            ->select('id')
            ->count();

        $data = ['data'=>self::convertObjectToArray($result),'count'=>$count];
        return self::convertObjectToArray($data);

    }


    public function getXsTotalList($where,$search,$page,$limit)
    {

        $result =  DB::table('v_xs_total')
            ->where(function($query) use($search) {
                if (!empty($search['date'])) {
                    $query->where('data_time',$search['date']);
                }
                if (!empty($search['yao_customer_name'])) {
                    $query->where('yao_customer_name', 'like', '%' . $search['yao_customer_name'] . '%');
                }
                if (!empty($search['ytx_code'])) {
                    $query->where('ytx_code',  $search['ytx_code']);
                }
            })
            ->select('*')
            ->offset($page)->limit($limit)
            ->get()->toArray();

        $count = DB::table('v_xs_total')
            ->where(function($query) use($where) {
                if (!empty($search['date'])) {
                    $query->where('date_time',$search['date']);
                }
                if (!empty($search['yao_customer_name'])) {
                    $query->where('yao_customer_name', 'like', '%' . $search['yao_customer_name'] . '%');
                }
                if (!empty($search['ytx_code'])) {
                    $query->where('ytx_code',  $search['ytx_code']);
                }

            })
            ->select('id')
            ->count();

        $data = ['data'=>self::convertObjectToArray($result),'count'=>$count];
        return self::convertObjectToArray($data);

    }



    public function getInventoryList($where)
    {
        $result =  DB::table('v_rk')
            ->where(function($query) use($where) {
                //开始时间
                if (!empty($where['start_time'])) {
                    $query->where('date_time', '>=', $where['start_time']);
                }
                //结束时间
                if (!empty($where['end_time'])) {
                    $query->where('date_time', '<=', $where['end_time']);
                }
            })
            ->select('*')
            ->get()->toArray();

        $data = ['data'=>self::convertObjectToArray($result)];
        return self::convertObjectToArray($data);

    }


    public function getInventoryXsData($where)
    {
        $result =  DB::table('v_xs')
            ->where(function($query) use($where) {
                //开始时间
                if (!empty($where['start_time'])) {
                    $query->where('date', '>=', $where['start_time']);
                }
                //结束时间
                if (!empty($where['end_time'])) {
                    $query->where('date', '<=', $where['end_time']);
                }
            })
            ->select('*')
            ->get()->toArray();

        $data = ['data'=>self::convertObjectToArray($result)];
        return self::convertObjectToArray($data);

    }

    public function getSubjectFieldData($where)
    {
        $result =  DB::table('v_subject_field')
            ->where($where)
            ->select('ytx_code','ytx_subject','kd_code','kd_subject','auxiliary_calculation')
            ->first();

        if($result){
            return self::convertObjectToArray($result);
        }else{
            return $result;
        }

    }

    public function getSupplierFieldData($where)
    {
        $result =  DB::table('v_supplier_field')
            ->where($where)
            ->select('*')
            ->first();
        if($result){
            return self::convertObjectToArray($result);
        }else{
            return $result;
        }

    }

    public function getCustomerFieldData($where)
    {
        $result =  DB::table('v_customer_field')
            ->where($where)
            ->select('*')
            ->first();
        if($result){
            return self::convertObjectToArray($result);
        }else{
            return $result;
        }

    }

    public function getDetailsDataList($where,$search,$page,$limit)
    {

        $result =  DB::table('v_rk')
            ->where(function($query) use($search) {
                if (!empty($search['date_time'])) {
                    $query->where('date_time',$search['date_time']);
                }
                if (!empty($search['product_name'])) {
                    $query->where('product_name', 'like', '%' . $search['product_name'] . '%');
                }
                if (!empty($search['product_code'])) {

                    $query->where('product_code',  $search['product_code']);
                }
            })
            ->where($where)
            ->select('*')
            ->orderBy('date_time','desc')
            ->offset($page)->limit($limit)
            ->get()->toArray();

        $count = DB::table('v_rk')
            ->where(function($query) use($search) {
                if (!empty($search['date_time'])) {
                    $query->where('date_time',$search['date_time']);
                }
                if (!empty($search['product_name'])) {
                    $query->where('product_name', 'like', '%' . $search['product_name'] . '%');
                }
                if (!empty($search['product_code'])) {
                    $query->where('product_code',  $search['product_code']);
                }
            })
            ->select('id')
            ->where($where)
            ->count();

        $data = ['data'=>$result,'count'=>$count];
        return self::convertObjectToArray($data);

    }




    public function getXsDetailsDataList($where,$search,$page,$limit)
    {
        $result =  DB::table('v_xs')
            ->where(function($query) use($search) {
                if (!empty($search['date'])) {
                    $query->where('date',$search['date']);
                }
                if (!empty($search['product_name'])) {
                    $query->where('product_name', 'like', '%' . $search['product_name'] . '%');
                }
                if (!empty($search['product_code'])) {

                    $query->where('product_code',  $search['product_code']);
                }
            })
            ->where($where)
            ->select('*')
            ->orderBy('date','desc')
            ->offset($page)->limit($limit)
            ->get()->toArray();

        $count = DB::table('v_xs')
            ->where(function($query) use($search) {
                if (!empty($search['date_time'])) {
                    $query->where('date',$search['date_time']);
                }
                if (!empty($search['product_name'])) {
                    $query->where('product_name', 'like', '%' . $search['product_name'] . '%');
                }
                if (!empty($search['product_code'])) {
                    $query->where('product_code',  $search['product_code']);
                }
            })
            ->select('id')
            ->where($where)
            ->count();

        $data = ['data'=>$result,'count'=>$count];
        return self::convertObjectToArray($data);

    }

    public function getFieldData($table,$where)
    {
        $result = DB::table($table)
            ->select('*')
            ->where($where)
            ->get()->toArray();
        return self::convertObjectToArray($result);
    }



    public function getOneData($table,$where)
    {
        $result = DB::table($table)
            ->select('*')
            ->where($where)
            ->first();
        if($result){
            return self::convertObjectToArray($result);
        }else{
            return $result;
        }
    }

    protected static function convertObjectToArray($objects): array {
        if (is_array($objects)) {
            foreach ($objects as &$oneObject) {
                $oneObject = (array)$oneObject;
            }
        } elseif (is_object($objects)) {
            if ($objects instanceof Collection) {
                $objects = self::convertObjectToArray($objects->toArray());
            } else {
                $objects = (array)$objects;
            }
        }
        return $objects;
    }


    /**
     * @param $data
     * @return array
     * 入库凭证数据
     */
    public function getStoredData($data)
    {
        // 获取一次性时间戳以保证一致性
        $today = date('Y-m-d');
        $year = date('Y');
        $month = date('m');
        $prefixYearMonth = date('Y-m');
        // 随机凭证号
        $munber = 'RK' . mt_rand(10000, 99999);
        // 公共凭证字段模板
        $baseVoucherEntry = [
            'companyNumber' => 'H',
            'bookedDate' => $today,
            'bizDate' => $today,
            'periodYear' => $year,
            'periodNumber' => $month,
            'currencyNumber' => 'BB01',
            'creator' => '宋红云',
            'auditor' => '宋红云',
            'poster' => '宋红云',
        ];
        // 构建凭证列表
        $voucherList = [
            //无税金额
            // 借方条目
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 1,
                'accountNumber' => $data['account_number_1'],
                'entryDC' => '1',
                'debitAmount' => $data['tax_excluded_amount'],
                'originalAmount' => $data['tax_excluded_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['abstract_excluded'],
                "asstActName1"=> "一次性卫材-高值",
		        "asstActNumber1"=> "001001",
		        "asstActType1"=> "物料分类"


            ]),
            // 贷方条目
//            array_merge($baseVoucherEntry, [
//                'voucherType' => '贷',
//                'voucherNumber' => $munber,
//                'entrySeq' => 2,
//                'accountNumber' => $data['account_number_1'],
//                'entryDC' => '-1',
//                'creditAmount' => $data['amount'],
//                'originalAmount' => $data['amount'],
//                "voucherAbstract" => $prefixYearMonth . $data['abstract_excluded'],
//            ]),

            //税额
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 2,
                'accountNumber' => $data['account_number_2'],
                'entryDC' => '1',
                'debitAmount' => $data['tax_amount'],
                'originalAmount' => $data['tax_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['amount_abstract'],
                'creditAmount' => $data['tax_amount'],
                'originalAmount' => $data['tax_amount'],
            ]),
             //税额贷方
//            array_merge($baseVoucherEntry, [
//                'voucherType' => '贷',
//                'voucherNumber' => $munber,
//                'entrySeq' => 2,
//                'accountNumber' => $data['account_number_2'],
//                'entryDC' => '-1',
//                'creditAmount' => $data['tax_amount'],
//                'originalAmount' => $data['tax_amount'],
//                "voucherAbstract" => $prefixYearMonth . $data['amount_abstract'],
//            ]),
//
//
//            //含税金额
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 3,
                'accountNumber' => $data['account_number_3'],
                'entryDC' => '-1',
                'debitAmount' => $data['tax_included_amount'],
                'originalAmount' => $data['tax_included_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
                "asstActName1" => $data['jin_supplier_name'],
                "asstActNumber1" => $data['jin_supplier_code'],
                "asstActType1" => '供应商'
            ]),
//            // 税额贷方
//            array_merge($baseVoucherEntry, [
//                'voucherType' => '贷',
//                'voucherNumber' => $munber,
//                'entrySeq' => 3,
//                'accountNumber' => $data['account_number_3'],
//                'entryDC' => '-1',
//                'creditAmount' => $data['tax_included_amount'],
//                'originalAmount' => $data['tax_included_amount'],
//                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
//            ]),
        ];

        $certificateData = [
            'userInfo' => [
                'url' => 'http://218.29.86.210:6901/',
                'userName' => 'user',
                'slnName' => 'eas',
                'dcName' => 'zmjt06',
                'language' => 'L2',
                'dbType' => 0,
                'password' => 'Xinxibu2017.'
            ],
            'isVerify' => 0,
            'isImpCashflow' => 1,
            'voucherList' => $voucherList
        ];

        return $certificateData;
    }



    /**
     * @param $data
     * @return array
     * 入库凭证数据优化
     */
    public function getStoredTotalData($data,$dataTime,$field,$dataArr)
    {
        // 获取一次性时间戳以保证一致性
        $today = date('Y-m-d');
        $year = date('Y');
        $month = date('m');
        $prefixYearMonth = date('Y-m');
        // 随机凭证号
        $munber = 'RK' . mt_rand(10000, 99999);
        // 公共凭证字段模板
        $baseVoucherEntry = [
            'companyNumber' => 'H',
            'bookedDate' => $today,
            'bizDate' => $today,
            'periodYear' => $year,
            'periodNumber' => $month,
            'currencyNumber' => 'BB01',
            'creator' => '宋红云',
            'auditor' => '宋红云',
            'poster' => '宋红云',
        ];

        // 构建凭证列表
        $voucherList = [
            //无税金额
            // 借方条目
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 1,
                'accountNumber' => $data['account_number_1'],
                'entryDC' => '1',
                'debitAmount' => $data['tax_excluded_amount'],
                'originalAmount' => $data['tax_excluded_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['abstract_excluded'],
                "asstActName1"=> "一次性卫材-高值",
                "asstActNumber1"=> "001001",
                "asstActType1"=> "物料分类"

            ]),

            //税额
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 2,
                'accountNumber' => $data['account_number_2'],
                'entryDC' => '1',
                'debitAmount' => $data['tax_amount'],
                'originalAmount' => $data['tax_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['amount_abstract'],
                'creditAmount' => $data['tax_amount'],
                'originalAmount' => $data['tax_amount'],
            ]),

//            //含税金额
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 3,
                'accountNumber' => $data['account_number_3'],
                'entryDC' => '-1',
                'debitAmount' => $data['tax_included_amount'],
                'originalAmount' => $data['tax_included_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
                "asstActName1" => '河南淼漫医疗科技有限公司',
                "asstActNumber1" => '02-1379',
                "asstActType1" => '供应商'
            ]),

        ];

        foreach ($dataArr as $key=>$value){
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 4,
                'accountNumber' => $data['account_number_3'],
                'entryDC' => '-1',
                'debitAmount' => $value['tax_included_amount'],
                'originalAmount' => $value['tax_included_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
                "asstActName1" => $value['jin_supplier_name'],
                "asstActNumber1" => $value['jin_supplier_code'],
                "asstActType1" => '供应商'
            ]);
        }


        $certificateData = [
            'userInfo' => [
                'url' => 'http://218.29.86.210:6901/',
                'userName' => 'user',
                'slnName' => 'eas',
                'dcName' => 'zmjt06',
                'language' => 'L2',
                'dbType' => 0,
                'password' => 'Xinxibu2017.'
            ],
            'isVerify' => 0,
            'isImpCashflow' => 1,
            'voucherList' => $voucherList
        ];

        return $certificateData;
    }





    /**
     * @param $data
     * @return array
     * 入库收入凭证数据
     */
    public function getStoredOutData($data)
    {

        // 获取一次性时间戳以保证一致性
        $today = date('Y-m-d');
        $year = date('Y');
        $month = date('m');
        $prefixYearMonth = date('Y-m');
        // 随机凭证号
        $munber = 'CK' . mt_rand(10000, 99999);
        // 公共凭证字段模板
        $baseVoucherEntry = [
            'companyNumber' => 'H',
            'bookedDate' => $today,
            'bizDate' => $today,
            'periodYear' => $year,
            'periodNumber' => $month,
            'currencyNumber' => 'BB01',
            'creator' => '宋红云',
            'auditor' => '宋红云',
            'poster' => '宋红云',
        ];
        // 构建凭证列表
        $voucherList = [
            //无税金额
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 1,
                'accountNumber' => $data['account_number_1'],
                'entryDC' => '1',
                'debitAmount' => $data['income'],
                'originalAmount' => $data['income'],
                "voucherAbstract" => $prefixYearMonth . $data['abstract_excluded'],
                "asstActName1" => $data['jin_customer_name'],
                "asstActNumber1" => $data['jin_customer_code'],
                "asstActType1" => $data['asstActType2']
            ]),

            //销项税
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 2,
                'accountNumber' => $data['account_number_2'],
                'entryDC' => '1',
                'debitAmount' => $data['sales_tax'],
                'originalAmount' => $data['sales_tax'],
                "voucherAbstract" => $prefixYearMonth . $data['amount_abstract'],
                'creditAmount' => $data['sales_tax'],


            ]),

            //含税金额
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 3,
                'accountNumber' => $data['account_number_3'],
                'entryDC' => '-1',
                'debitAmount' => $data['tax_inclusive_amount'],
                'originalAmount' => $data['tax_inclusive_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
                "asstActName1" => $data['jin_customer_name'],
                "asstActNumber1" => $data['jin_customer_code'],
                "asstActType1" => $data['asstActType2']
            ]),

        ];

        $certificateData = [
            'userInfo' => [
                'url' => 'http://218.29.86.210:6901/',
                'userName' => 'user',
                'slnName' => 'eas',
                'dcName' => 'zmjt06',
                'language' => 'L2',
                'dbType' => 0,
                'password' => 'Xinxibu2017.'
            ],
            'isVerify' => 0,
            'isImpCashflow' => 1,
            'voucherList' => $voucherList
        ];

        return $certificateData;
    }



    /**
     * @param $data
     * @return array
     * 入库收入凭证数据
     */
    public function setCostOutData($data)
    {
        // 输入字段校验
        $requiredFields = [
            'account_number_1', 'income', 'abstract_excluded', 'jin_customer_name', 'jin_customer_code', 'asstActType1',
            'total_1', 'total_2', 'total_3', 'total_4', 'total_5'
        ];
        foreach ($requiredFields as $field) {
            if (!isset($data[$field])) {
                throw new InvalidArgumentException("Missing required field: {$field}");
            }
        }

        // 获取一次性时间戳以保证一致性
        $today = date('Y-m-d');
        $year = date('Y');
        $month = date('m');
        $prefixYearMonth = date('Y-m');
        $voucherAbstract = "转结".$prefixYearMonth."内部销售成本";
        // 随机凭证号
        $munber = 'CK' . mt_rand(100000, 999999); // 扩展位数降低重复率

        // 公共凭证字段模板
        $baseVoucherEntry = [
            'companyNumber' => 'H',
            'bookedDate' => $today,
            'bizDate' => $today,
            'periodYear' => $year,
            'periodNumber' => $month,
            'currencyNumber' => 'BB01',
            'creator' => '宋红云',
            'auditor' => '宋红云',
            'poster' => '宋红云',
        ];

        $voucherList = [];
        $seq = 1;
        $voucherList[] = array_merge($baseVoucherEntry, [
            'voucherType' => '记',
            'voucherNumber' => $munber,
            'entrySeq' => $seq++,
            'accountNumber' => $data['account_number_1'],
            'entryDC' => '1',
            'debitAmount' => $data['cost_total'],
            'originalAmount' => $data['cost_total'],
            "voucherAbstract" => $voucherAbstract,
            "asstActName1" => '河南美博医药科技有限公司',
            "asstActNumber1" => 'H',
            "asstActType1" => '部门'
        ]);

        // 原材料--卫生材料--一次性高值
        if ((float)$data['total_1'] != 0) {
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => $seq++,
                'accountNumber' => '1403.01',
                'entryDC' => '-1',
                'debitAmount' => $data['total_1'],
                'originalAmount' => $data['total_1'],
                "voucherAbstract" => $voucherAbstract,
                'creditAmount' => $data['total_1'],
                "asstActName1" => "一次性卫材-高值",
                "asstActNumber1" => "001001",
                "asstActType1" => "物料分类"
            ]);
        }

        // 原材料--卫生材料--其他
        if ((float)$data['total_2'] != 0) {
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => $seq++,
                'accountNumber' => '1403.01',
                'entryDC' => '-1',
                'debitAmount' => $data['total_2'],
                'originalAmount' => $data['total_2'],
                "voucherAbstract" => $voucherAbstract,
                'creditAmount' => $data['total_2'],
                "asstActName1" => "其他 T",
                "asstActNumber1" => "001002",
                "asstActType1" => "物料分类"
            ]);
        }

        // 条件添加 total_3
        if ((float)$data['total_3'] != 0) {
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => $seq++,
                'accountNumber' => '1403.01',
                'entryDC' => '-1',
                'debitAmount' => $data['total_3'],
                'originalAmount' => $data['total_3'],
                "voucherAbstract" => $voucherAbstract,
                'creditAmount' => $data['total_3'],
                "asstActName1" => "其他材料T",
                "asstActNumber1" => "001003",
                "asstActType1" => "物料分类"
            ]);
        }

        // 库存商品--西药
        if ((float)$data['total_4'] != 0) {
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => $seq++,
                'accountNumber' => '1405.03',
                'entryDC' => '-1',
                'debitAmount' => $data['total_4'],
                'originalAmount' => $data['total_4'],
                "voucherAbstract" => $voucherAbstract,
                'creditAmount' => $data['total_4'],
            ]);
        }

        // 库存商品--设备
        if ((float)$data['total_5'] != 0) {
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => $seq++,
                'accountNumber' => '1405.03',
                'entryDC' => '-1',
                'debitAmount' => $data['total_5'],
                'originalAmount' => $data['total_5'],
                "voucherAbstract" => $voucherAbstract,
                'creditAmount' => $data['total_5'],
            ]);
        }

        $certificateData = [
            'userInfo' => [
                'url' => 'http://218.29.86.210:6901/',
                'userName' => 'user',
                'slnName' => 'eas',
                'dcName' => 'zmjt06',
                'language' => 'L2',
                'dbType' => 0,
                'password' => 'Xinxibu2017.'
            ],
            'isVerify' => 0,
            'isImpCashflow' => 1,
            'voucherList' => $voucherList
        ];

        return $certificateData;
    }



    /**
     * @param $data
     * @return array
     * 入库收入凭证数据
     */
    public function setStoredOutData($data,$dataArr,$dataTime)
    {

        // 获取一次性时间戳以保证一致性
        $today = date('Y-m-d');
        $year = date('Y');
        $month = date('m');
        $prefixYearMonth = $dataTime;


        // 随机凭证号
        $munber = 'CK' . mt_rand(10000, 99999);
        // 公共凭证字段模板
        $baseVoucherEntry = [
            'companyNumber' => 'H',
            'bookedDate' => $today,
            'bizDate' => $today,
            'periodYear' => $year,
            'periodNumber' => $month,
            'currencyNumber' => 'BB01',
            'creator' => '宋红云',
            'auditor' => '宋红云',
            'poster' => '宋红云',
        ];
        // 构建凭证列表
        $voucherList = [
            //无税金额
//            array_merge($baseVoucherEntry, [
//                'voucherType' => '记',
//                'voucherNumber' => $munber,
//                'entrySeq' => 1,
//                'accountNumber' => $data['account_number_1'],
//                'entryDC' => '-1',
//                'debitAmount' => $data['income'],
//                'originalAmount' => $data['income'],
//                "voucherAbstract" => $prefixYearMonth . $data['abstract_excluded'],
//                "asstActName1" => '郑州大卫城欧华医疗美容有限公司',
//                "asstActNumber1" => 'F02',
//                "asstActType1" => $data['asstActType2']
//            ]),

            //销项税
            array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 2,
                'accountNumber' => $data['account_number_2'],
                'entryDC' => '-1',
                'debitAmount' => $data['amount'],
                'originalAmount' => $data['amount'],
                "voucherAbstract" => $prefixYearMonth . $data['amount_abstract'],
                'creditAmount' => $data['amount'],


            ]),

            //含税金额
//            array_merge($baseVoucherEntry, [
//                'voucherType' => '记',
//                'voucherNumber' => $munber,
//                'entrySeq' => 3,
//                'accountNumber' => $data['account_number_3'],
//                'entryDC' => '1',
//                'debitAmount' => $data['tax_included_amount'],
//                'originalAmount' => $data['tax_included_amount'],
//                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
//                "asstActName1" => '郑州大卫城欧华医疗美容有限公司',
//                "asstActNumber1" => 'F02',
//                "asstActType1" => $data['asstActType2']
//            ]),

        ];
        //收入明细
        foreach ($dataArr as $key=>$value){
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 1,
                'accountNumber' => $data['account_number_1'],
                'entryDC' => '-1',
                'debitAmount' => $value['income'],
                'originalAmount' => $value['income'],
                "voucherAbstract" => $prefixYearMonth . $data['abstract_excluded'],
                "asstActName1" => $value['jin_customer_name'],
                "asstActNumber1" => $value['jin_customer_code'],
                "asstActType1" => $data['asstActType2']
            ]);
        }
        //含税金额明细 暂估入库
        foreach ($dataArr as $key=>$value){
            $voucherList[] = array_merge($baseVoucherEntry, [
                'voucherType' => '记',
                'voucherNumber' => $munber,
                'entrySeq' => 4,
                'accountNumber' => $data['account_number_3'],
                'entryDC' => '1',
                'debitAmount' => $value['tax_inclusive_amount'],
                'originalAmount' => $value['tax_inclusive_amount'],
                "voucherAbstract" => $prefixYearMonth . $data['included_abstract'],
                "asstActName1" => $value['jin_customer_name'],
                "asstActNumber1" => $value['jin_customer_code'],
                "asstActType1" => '客户'
            ]);
        }

        $certificateData = [
            'userInfo' => [
                'url' => 'http://218.29.86.210:6901/',
                'userName' => 'user',
                'slnName' => 'eas',
                'dcName' => 'zmjt06',
                'language' => 'L2',
                'dbType' => 0,
                'password' => 'Xinxibu2017.'
            ],
            'isVerify' => 0,
            'isImpCashflow' => 1,
            'voucherList' => $voucherList
        ];

        return $certificateData;
    }

}
